package com.ruoyi.material.service.impl;

import java.util.List;

import com.ruoyi.common.constant.material.PurchaseConstants;
import com.ruoyi.material.domain.FoodType;
import com.ruoyi.material.domain.WarehouseStock;
import com.ruoyi.material.mapper.FoodTypeMapper;
import com.ruoyi.material.mapper.WarehouseStockMapper;
import com.ruoyi.material.service.IWarehouseStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 仓库库存Service业务层处理
 *
 * @author wng
 * @date 2024-08-04
 */
@Service
public class WarehouseStockServiceImpl implements IWarehouseStockService {
    @Resource
    private WarehouseStockMapper warehouseStockMapper;

    @Resource
    private FoodTypeMapper foodTypeMapper;

    /**
     * 查询仓库库存
     *
     * @param id 仓库库存主键
     * @return 仓库库存
     */
    @Override
    public WarehouseStock selectWarehouseStockById(Long id) {
        WarehouseStock item = warehouseStockMapper.selectWarehouseStockById(id);
        FoodType foodType = foodTypeMapper.selectFoodTypeById(item.getfTypeSub());
        if (foodType != null) {
            item.getParams().put("fTypeSubName", foodType.getTypeName());
            item.setfTypeSubName(foodType.getTypeName());
        }
        item.setfTypeName(item.getfType().getTypeName());
        return item;
    }

    /**
     * 查询仓库库存列表
     *
     * @param warehouseStock 仓库库存
     * @return 仓库库存
     */
    @Override
    public List<WarehouseStock> selectWarehouseStockList(WarehouseStock warehouseStock) {
        List<WarehouseStock> warehouseStocks = warehouseStockMapper.selectWarehouseStockList(warehouseStock);
        warehouseStocks.forEach(item -> {
            FoodType foodType = foodTypeMapper.selectFoodTypeById(item.getfTypeSub());
            if (foodType != null) {
                item.getParams().put("fTypeSubName", foodType.getTypeName());
                item.setfTypeSubName(foodType.getTypeName());
            }
            item.setfTypeName(item.getfType().getTypeName());
        });
        return warehouseStocks;
    }

    /**
     * 新增仓库库存
     *
     * @param warehouseStock 仓库库存
     * @return 结果
     */
    @Override
    public int insertWarehouseStock(WarehouseStock warehouseStock) {
        return warehouseStockMapper.insertWarehouseStock(warehouseStock);
    }

    /**
     * 修改仓库库存
     *
     * @param warehouseStock 仓库库存
     * @return 结果
     */
    @Override
    public int updateWarehouseStock(WarehouseStock warehouseStock) {
        return warehouseStockMapper.updateWarehouseStock(warehouseStock);
    }

    /**
     * 批量删除仓库库存
     *
     * @param ids 需要删除的仓库库存主键
     * @return 结果
     */
    @Override
    public int deleteWarehouseStockByIds(Long[] ids) {
        return warehouseStockMapper.deleteWarehouseStockByIds(ids);
    }

    /**
     * 删除仓库库存信息
     *
     * @param id 仓库库存主键
     * @return 结果
     */
    @Override
    public int deleteWarehouseStockById(Long id) {
        return warehouseStockMapper.deleteWarehouseStockById(id);
    }
}
